#pragma once
#include <string>

using namespace std;

class MachineReadParam;
class MachineWirteParam;
bool getReadParam(string ip,MachineReadParam &param);//实时读取某台机器的所有参数


//获取某台机器的写参数，（写参数被缓存了，因为485写参数时，只支持将所有参数写入，而对前端不友好，所有缓存所有参数，实际前端修改参数，只需要修改其中某一项）
MachineWirteParam *getWriteParam(string ip);


//—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
enum Direction
{
    D_stop = 0,//0停止
    D_forward = 1,//前进
    D_forward_right = 2,//前进右转
    D_trun_right = 3,//右掉头
    D_back_right = 4,//后退右转
    D_back = 5,//后退
    D_bck_left = 6,//后退左转
    D_turn_left= 7,//左掉头
    D_forward_left = 8,//前进左转
    D_Invalid//无效状态，
};

class MachineReadParam //读取参数
{
public:
    MachineReadParam(){};
public:
    bool getFatalWarn();//获取急停状态
    bool isLoseNet();//是否掉网
    Direction getDirection();
    unsigned int getLeftSpeed();
    unsigned int getRightSpeed();

    bool getMashineState();//主机启停状态
   
public:
    bool m_fatalWarn ;
    bool m_bLoseNet;
    Direction m_direction;//方向 0停止 1前进 2前进右转 3右掉头 4后退右转 5后退 6后退左转 7左掉头 8前进左转
    int m_leftSpeed = -1;//左轮速度 取值范围0~3000 单位rpm
    int m_rightSpeed = -1;//右轮速度 取值范围0~3000 单位rpm
    bool m_bStart;


};


class MachineWirteParam //写参数
{
public:
    MachineWirteParam(string ip){m_ip = ip;}
public:
    void setFatalWarn(bool b);//设置急停
    void setlightWarn(bool b);//设置轻度报警
    void setDirection(Direction  d);
    void setLeftSpeed(unsigned int speed);
    void setRightSpeed(unsigned int speed);
    void setEnable(bool b);
    string getIp();
    bool exec();

private:
    bool m_fatalWarn = false;
    bool m_lightWarn = false; //轻度报警 1有效
    Direction m_direction =D_Invalid;//方向 0停止 1前进 2前进右转 3右掉头 4后退右转 5后退 6后退左转 7左掉头 8前进左转
    unsigned short m_leftSpeed = 0;//左轮速度 取值范围0~3000 单位rpm
    unsigned short m_rightSpeed = 0;//右轮速度 取值范围0~3000 单位rpm
    bool m_enable = false;
    string m_ip;
};